efform_onload = function ()
{
	var info = new EiInfo();
	info.set("parentTypes",$('#parentTypes').val());
	info.set("childTypes",$('#childTypes').val()); 
	EiCommunicator.send("ZMCSF1", "query", info, ajax_chang_callback);
}; 
var ajax_chang_callback = {
	onSuccess : function(eiInfo) {
		efwindow.hide();
		var grid = efgrid.getGridObject("ef_grid_r");
		grid.refresh(eiInfo);
	},
	onFail : function(eMsg) {
	}
}; 
button_query_onclick = function () 
{   	
	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCSF1","query");
}
button_insert_onclick = function () {
	if (isSelected("ef_grid_r") == 0)return; 
//	efgrid.submitForm( "ef_grid_r", "ZM","ZMCSF1","insert",true);
	//以下为行增有重复性校验
	var info = getSCZXEiInfos("ZMCSF1","ef_grid_r");
	if (null != info) { 
		EiCommunicator.send("ZMCSF1", "validate", info, validate_callback);
	}
}
button_update_onclick = function() {
	if (isSelected("ef_grid_r") == 0)return; 
//	efgrid.submitForm( "ef_grid_r", "ZM","ZMCSF1","update",true);
	//以下为行增有重复性校验
	var info = getSCZXEiInfos("ZMCSF1","ef_grid_r");
	if (null != info) { 
		EiCommunicator.send("ZMCSF1", "validate", info, validate_callback);
	}
}
button_delete_onclick = function (){ 
	if (isSelected("ef_grid_r") == 0)return; 
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
//		efgrid.submitForm( "ef_grid_r", "ZM","ZMCSF1","delete",true);
		//以下为行增有重复性校验
		var info = getSCZXEiInfos("ZMCSF1","ef_grid_r");
		if (null != info) { 
			EiCommunicator.send("ZMCSF1", "validate1", info, validate2_callback);
		}

	});
} 
button_modifystart_onclick = function (){ 
	if (isSelected("ef_grid_r") == 0)return; 
//	efgrid.submitForm( "ef_grid_r", "ZM","ZMCSF1","modifyStart",true);
	var info = getSCZXEiInfos("ZMCSF1","ef_grid_r");
	if (null != info) { 
		EiCommunicator.send("ZMCSF1", "validate1", info, validate2_callback);
	}
} 
button_modifystop_onclick = function (){ 
	if (isSelected("ef_grid_r") == 0)return; 
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCSF1","modifyStop",true);
} 
var validate_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
			//	var info = getSCZXEiInfos("ZMCSF1","ef_grid_r");
				if(eiInfo.get("efCurButtonEname")!="INSERT"){
					EiCommunicator.send("ZMCSF1", "validate1", eiInfo, validate2_callback);
				}else if(eiInfo.get("efCurButtonEname")=="INSERT"){
					efgrid.submitForm( "ef_grid_r", "ZM","ZMCSF1","insert",true);
				}
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}

var validate2_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					oper="update";
					
					efgrid.submitForm( "ef_grid_r", "ZM","ZMCSF1",oper,true);
				}else if(eiInfo.get("efCurButtonEname")=="MODIFYSTART"){
					oper="modifyStart";
					efgrid.submitForm( "ef_grid_r", "ZM","ZMCSF1",oper,true);
				}else if(eiInfo.get("efCurButtonEname")=="DELETE"){
					efgrid.submitForm( "ef_grid_r", "ZM","ZMCSF1","delete",true);
				}
				

			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
/*efgrid_afterAddNewRow = function(grid_id){ 
	var childTypes=$('#childTypes').val();
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if(grid_id=="ef_grid_r")
	{
		for(var i = 0 ; i < rows.length;i++){
			grid.setCellValue(rows[i],0,childTypes,TYPE_DATA);
			grid.setCellValue(rows[i],1,0,TYPE_DATA);
			grid.setCellValue(rows[i],2,0,TYPE_DATA);
		}
	}
}*/ 
//单元格编辑后回调的方法
efgrid_onDataCellSaved = function( grid_id, row_index, col_index, cell_value ) 
{
	  var grid = efgrid.getGridObject( grid_id ); 
	  if( col_index == 8) 
	  { 
		  var info=_getEi();
		  var eiBlock=info.getBlock("cmes.cs.engineeringParentId");
		  for(var i=0;i<eiBlock.getRows().length;i++)
		  {
			  var _display = eiBlock.getCell(i,"display");
 			  var _value = eiBlock.getCell(i,"value");
			  var _types = eiBlock.getCell(i,"types");
			  if(_value==cell_value)
			  {
				  if(_types=="GZM")grid.setCellValue(row_index,3,"T_CI_WORKINGFACE",TYPE_DATA);
				  else if (_types=="HD")grid.setCellValue(row_index,3,"T_CI_ROADWAY",TYPE_DATA);
				  else grid.setCellValue(row_index,3,"T_CI_OTHERDESIGN",TYPE_DATA);
				  grid.refreshCell( row_index, 3 , TYPE_DATA ); 
			  }
		  }
	  } 
}

efgrid_afterAddNewRow = function(grid_id){ 
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
    
	if(grid_id=="ef_grid_r")
	{
		var parentTypes=$('#parentTypes').val();
		var childTypes=$('#childTypes').val();
		
		for(var i = 0 ; i < rows.length;i++){
			grid.setCellValue(rows[i],0,0,TYPE_DATA); 
			grid.setCellValue(rows[i],1,childTypes,TYPE_DATA);
		//	grid.setCellValue(rows[i],2,parentTypes,TYPE_DATA);
			 switch (parentTypes)
	          {
	              case "0":
	            	  grid.setCellValue(rows[i],9,"吨",TYPE_DATA);
	                  break;
	              case "1":
	            	  grid.setCellValue(rows[i],9,"米",TYPE_DATA);
	                  break;
	              case "2":
	                  if ("打钻"==childTypes)
	                	  grid.setCellValue(rows[i],9,"米",TYPE_DATA);
	                  else if ("抽采"==childTypes)
	                	  grid.setCellValue(rows[i],9,"万立方米",TYPE_DATA);
	                  else if ("管路安装"==childTypes)
	                	  grid.setCellValue(rows[i],9,"米",TYPE_DATA);
	                  else
	                	  grid.setCellValue(rows[i],9,"个",TYPE_DATA);
	                  break;
	              default:
	                  break;
	          }
		}
	}
}